package alvin.hwang.asyntree;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class SomethingTest extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String msg = "afafasfas\ndfasfasfdaf";
		System.out.println(msg);
		msg = msg.replaceAll("\n", "\\n");
		System.out.println(msg);
		boolean isSuccessful = true;
		response.setContentType("text/html; charset=GBK");
		Writer writer = response.getWriter();
		writer.write("<script type='text/javascript'>");
		writer.write("try {");
		writer.write("customCallback('" + msg + "'," + isSuccessful + ");");
		writer.write("} catch (e) {");
		writer.write("window.alert('" + msg + "');");
		writer.write("window.returnValue='" + isSuccessful + "';");
		writer.write("window.close();");
		writer.write("}");
		writer.write("</script>");
		writer.flush();
		writer.close();
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
